{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n回顾：逻辑回归中，处理多分类问题使用OVR/OVO  \\n'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "回顾：逻辑回归中，处理多分类问题使用OVR/OVO  \n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "#创建10分类问题\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets\n",
    "digits=datasets.load_digits()\n",
    "X=digits.data\n",
    "y=digits.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.8)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9478442280945758"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#默认使用OVR\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "log_reg=LogisticRegression(max_iter=1000000)\n",
    "log_reg.fit(x_train,y_train)\n",
    "log_reg.score(x_test,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'precision_score无法评估多分类问题'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"precision_score无法评估多分类问题\"\"\"\n",
    "# from sklearn.metrics import precision_score\n",
    "# precision_score(y_test,log_reg.predict(x_test))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对于混淆矩阵，天然支持多分类问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[136,   0,   0,   0,   1,   0,   0,   0,   0,   0],\n",
       "       [  0, 141,   3,   2,   0,   0,   0,   0,   3,   2],\n",
       "       [  0,   4, 131,   0,   0,   0,   1,   0,   0,   0],\n",
       "       [  1,   0,   0, 139,   0,   4,   0,   1,   5,   1],\n",
       "       [  0,   1,   0,   0, 150,   0,   0,   3,   3,   1],\n",
       "       [  0,   1,   0,   0,   0, 130,   1,   1,   0,   3],\n",
       "       [  1,   0,   0,   0,   0,   2, 144,   0,   0,   0],\n",
       "       [  0,   1,   0,   0,   2,   0,   0, 135,   3,   1],\n",
       "       [  0,   4,   1,   2,   0,   1,   0,   1, 126,   0],\n",
       "       [  0,   1,   0,   1,   1,   1,   0,   0,  10, 131]], dtype=int64)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "\"\"\"十个数，所以是10X10矩阵，解读思路和2X2相同。行为真值，列为预测值\n",
    "对角线：是i，预测也对了预测的是i\n",
    "\"\"\"\n",
    "confusion_matrix(y_test,log_reg.predict(x_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x245ac0534f0>"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZoAAAGkCAYAAAAIduO+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAWFklEQVR4nO3df6jV9f3A8dfxplcn917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s+eHbfeemtERJx++unx6quvxj333CM0n/Lwww/HAw88EGvXro3p06fHSy+9FEuWLIlJkyYdtuvUcKE5+uijo6mpKbZv3z5g+/bt2+PYY48taKryuuaaa+Lxxx+PZ599No4//viixymdzZs3x44dO+KMM87Yu62vry+effbZuOuuu6K3tzeampoKnLA8jjvuuDjllFMGbJs2bVr87ne/K2iicrr++utj2bJlcfnll0dExMyZM+Ott96Krq6uwzY0DfcezZgxY+LMM8+MdevW7d3W398f69ati3PPPbfAycqlVqvFNddcE4888kj86U9/io6OjqJHKqXzzz8/XnnllXjppZf23mbPnh3z58+Pl156SWQ+Ze7cuYM+Ir9169Y44YQTCpqonD788MMYNWrgU2tTU1P09/cXNFHxGu6IJiJi6dKlsWDBgpg9e3acffbZcccdd8Tu3btj4cKFRY9WGp2dnbF27dp49NFHo6WlJbZt2xYREW1tbTFu3LiCpyuPlpaWQe9bjR8/PiZMmOD9rP9x3XXXxZw5c+LWW2+Nb3/727Fx48ZYvXp1rF69uujRSuWSSy6JFStWxJQpU2L69Onx4osvxu233x5XXnll0aMVp9ag7rzzztqUKVNqY8aMqZ199tm1DRs2FD1SqUTEPm/3339/0aOV3le/+tXa4sWLix6jlP7whz/UZsyYUWtubq5NnTq1tnr16qJHKp1qtVpbvHhxbcqUKbWxY8fWvvSlL9V+9KMf1Xp7e4serTAN+e9oAGgcDfceDQCNRWgASCU0AKQSGgBSCQ0AqYQGgFQNG5re3t748Y9/HL29vUWPUnrWamis09BYp6GzVv/VsP+OplqtRltbW/T09ERra2vR45SatRoa6zQ01mnorNV/NewRDQCNQWgASHXIT6rZ398f77zzTrS0tESlUhn296lWqwP+y/5Zq6GxTkNjnYZupK9VrVaLnTt3xqRJkwadsfrTDvl7NP/+979j8uTJh3KXACTq7u7+zOtdHfIjmpaWloiI2LJly97/L4OTTz656BEAGtLnPZcf8tB88nJZS0tLqUJDYzuQl2GzNOgHOqFun/fnz4cBAEglNACkEhoAUgkNAKmEBoBUQgNAKqEBIJXQAJBKa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GG26I73//+7Fjx46YNGlSfO9734sbb7wxaz4AGlyldoj/WX+1Wo22trZDucshGTNmTNEjDLJnz56iR9in/335tAz6+vqKHmGQSqVS9AiDlPEsHmVcp4iI1157regRBpk2bVrRI+xTT09PtLa27vfr5XvGAGBEERoAUgkNAKmEBoBUQgNAKqEBIJXQAJBKaABIJTQApBIaAFIJDQCphAaAVHWdvXkkK+MJLMt4AsSIKOX1h8p6YkY+X1l/zufMmVP0CIP885//LHqEAXbu3BmzZs363Ps5ogEgldAAkEpoAEglNACkEhoAUgkNAKmEBoBUQgNAKqEBIJXQAJBKaABIJTQApBIaAFIJDQCphAaAVEIDQCqhASCV0ACQSmgASCU0AKQSGgBSCQ0AqYQGgFRCA0AqoQEgldAAkEpoAEglNACkEhoAUgkNAKmEBoBUQgNAKqEBIJXQAJBKaABIdcSh3mGtVjvUuxySss5VRtaKw0EZf8537txZ9AgD7Nq1KyI+f60OeWjKtlAA+/LBBx8UPcIgs2bNKnqEfdq5c2e0tbXt9+uV2iHOdn9/f7zzzjvR0tISlUpl2N+nWq3G5MmTo7u7O1pbWw/ihCOPtRoa6zQ01mnoRvpa1Wq12LlzZ0yaNClGjdr/OzGH/Ihm1KhRcfzxxx+079fa2joifwMzWKuhsU5DY52GbiSv1WcdyXzChwEASCU0AKRq2NA0NzfHTTfdFM3NzUWPUnrWamis09BYp6GzVv91yD8MAMDhpWGPaABoDEIDQCqhASCV0ACQSmgASCU0AKQSGgBSCQ0Aqf4PpJh/SS4IZhIAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 480x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#绘制出矩阵\n",
    "cfm=confusion_matrix(y_test,log_reg.predict(x_test))\n",
    "plt.matshow(cfm,cmap=plt.cm.gray)#使用灰色映射，越亮预测到此点数量（值）越大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "观察所犯的错误\n",
    "\"\"\"\n",
    "row_sums=np.sum(cfm,axis=1)#求出每一行的和\n",
    "err_matrix=cfm/row_sums\n",
    "np.fill_diagonal(err_matrix,0)#把对角线都变成0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "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x/1Mf39/VEul4fcADhxVHVFs3LlyiiXyzFjxoxobGyMgYGBWL16dSxatOioj+nq6oq77777cw8FoD5VdUXzxBNPxObNm2PLli2xa9eu2LRpU/zsZz+LTZs2HfUxq1atilKpdPjW29v7uUcDUD+quqK5/fbbY+XKlXHDDTdERMTs2bPjnXfeia6urli8ePERH9PU1BRNTU2ffykAdamqK5qPPvooxo0b+pDGxsYYHBw8rqMAGDuquqK59tprY/Xq1TFt2rSYOXNmvPbaa3H//ffHTTfdlLUPgDpXVWgeeOCBuOOOO+L73/9+9PX1xdSpU+M73/lO3HnnnVn7AKhzVYWmubk51q5dG2vXrk2aA8BY473OAEglNACkEhoAUgkNAKmEBoBUQgNAKqEBIJXQAJBKaABIJTQApBIaAFIJDQCpqnpTzbFs69atRU8Ypq+vr+gJRzQwMFD0hGFOP/30oidwjPbt21f0hCOqVCpFTximoaGh6AnHxBUNAKmEBoBUQgNAKqEBIJXQAJBKaABIJTQApBIaAFIJDQCphAaAVEIDQCqhASCV0ACQSmgASCU0AKQSGgBSCQ0AqYQGgFRCA0AqoQEgldAAkEpoAEglNACkEhoAUgkNAKmEBoBUQgNAKqEBIJXQAJBKaABIJTQApBIaAFIJDQCphAaAVEIDQKqTRvsJK5XKaD/liAwODhY9oW7U4rmqxf+uavE8MXLlcrnoCXXjs/78jXpoDh48ONpPOSLvv/9+0RPqhnPFiaC1tbXoCXXj4MGDn3q+Giqj/L+Cg4OD8d5770Vzc3M0NDQc88cpl8vR0dERvb290dLSchwXjj3O1cg4TyPjPI3cWD9XlUolDh48GFOnTo1x447+nZhRv6IZN25cnHHGGcft47W0tIzJf4EZnKuRcZ5GxnkaubF8rkZy5efFAACkEhoAUtVtaJqamuKuu+6KpqamoqfUPOdqZJynkXGeRs65+o9RfzEAACeWur2iAaA+CA0AqYQGgFRCA0AqoQEgldAAkEpoAEglNACk+j+nGTsYlGPqwQAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 480x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"绘制:越亮代表犯错越多\n",
    "比如（8，1）最亮：很多真值为8的预测为1了\n",
    "\"\"\"\n",
    "plt.matshow(err_matrix,cmap=plt.cm.gray)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "思考：为何把8错认为1？？\n",
    "可能数据也出了问题：检查数据、特征工程\n",
    "\n",
    "\"\"\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
